Skip to content

fix: upload event plans in headless runs - #891

Merged
fercgomes merged 7 commits into
mainfrom
posthog-code/stream-event-plan-headless
Jul 16, 2026
Merged

fercgomes merged 7 commits into
mainfrom
posthog-code/stream-event-plan-headless

Conversation

@fercgomes

@fercgomes fercgomes commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Wizard-created custom events are not visible to cloud runs until real traffic arrives because the event plan was only mirrored by the rendered TUI.

Why: Headless runs need to stream the same planned event metadata as interactive runs so downstream setup can surface event definitions immediately.

Changes

  • Move event-plan watching into shared runner machinery, enabled explicitly by the integration program.
  • Guarantee a bounded final refresh before the terminal session push, while ignoring unchanged artifacts present at run startup.
  • Validate file type, size, event count, names, and descriptions; debounce parent-directory watch events.
  • Keep the TUI as a store-only consumer and document the resolved QA findings in QAREPORT.md.

Test plan

  • pnpm build
  • pnpm test — 98 files, 1,328 tests passed
  • pnpm fix
  • Focused watcher/task-stream suite — 41 tests passed

Created with PostHog Code

@github-actions

Copy link
Copy Markdown

🧙 Wizard CI

Run the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands:

Test all apps:

  • /wizard-ci all

Test all apps in a directory:

  • /wizard-ci basic-integration
  • /wizard-ci mcp-analytics
  • /wizard-ci revenue

Test an individual app:

  • /wizard-ci basic-integration/android
  • /wizard-ci basic-integration/angular
  • /wizard-ci basic-integration/astro
Show more apps
  • /wizard-ci basic-integration/django
  • /wizard-ci basic-integration/fastapi
  • /wizard-ci basic-integration/flask
  • /wizard-ci basic-integration/javascript-node
  • /wizard-ci basic-integration/javascript-web
  • /wizard-ci basic-integration/laravel
  • /wizard-ci basic-integration/next-js
  • /wizard-ci basic-integration/nuxt
  • /wizard-ci basic-integration/python
  • /wizard-ci basic-integration/rails
  • /wizard-ci basic-integration/react-native
  • /wizard-ci basic-integration/react-router
  • /wizard-ci basic-integration/sveltekit
  • /wizard-ci basic-integration/swift
  • /wizard-ci basic-integration/tanstack-router
  • /wizard-ci basic-integration/tanstack-start
  • /wizard-ci basic-integration/vue
  • /wizard-ci mcp-analytics/custom-dispatcher
  • /wizard-ci mcp-analytics/typescript-sdk
  • /wizard-ci revenue/stripe

Results will be posted here when complete.

@fercgomes
fercgomes marked this pull request as ready for review July 14, 2026 14:31
@fercgomes
fercgomes requested a review from a team as a code owner July 14, 2026 14:31
@fercgomes
fercgomes requested a review from gewenyu99 July 14, 2026 14:31
@gewenyu99

Copy link
Copy Markdown
Collaborator

@fercgomes Before I review, I think you should stream the [STATUS] updates we parse instead and display at the bottom of the wizard screen. That's what the wizard is actively working on.

You don't need to stream the even plan at all, it is set once and not changed as of right now. If we make it such that it changes (not at all planned), we can add this in later. For now you can upload once when it's loaded.

@fercgomes fercgomes changed the title fix: stream event plans in headless runs fix: upload event plans in headless runs Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the event-plan part of this feedback: the wizard now captures the first non-empty valid plan, stores it, and stops watching, so later file writes are not streamed.

I did not add [STATUS] to the wire payload because the current PostHog UpsertWizardSessionRequest / WizardSessionDTO contract has no status field, and the generated frontend session DTO has nowhere to render it. Sending an extra field from this repo would make the session endpoint return 400 and stop all task/phase updates. That needs a coordinated PostHog backend + frontend contract change first; once that field lands, the wizard already parses these updates and can wire them through safely.

@gewenyu99

Copy link
Copy Markdown
Collaborator

Great, I'll review the relevant parts in this PR, thanks!

@gewenyu99 gewenyu99 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noice. Some comments for you to consider but non blocking (other than QA report lol

Comment thread QAREPORT.md Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plz remove <3

Comment thread src/lib/file-watcher.ts Outdated

try {
attachWatch();
read(true);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this read(true) calls onUpdate synchronously before we return the handle. so if a caller stop()s from inside onUpdate (EventPlanWatcher does) it just no-ops + leaks the watcher. only safe today bc ignoreInitialFile: true. can we guard the callback or at least leave a comment so future me doesn't step on it? 🙏

Comment thread src/lib/file-watcher.ts
}
if (
options.maxFileSizeBytes !== undefined &&
stat.size > options.maxFileSizeBytes

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we silently eat oversized files here (+ bad json in the catch below) → empty event plan tab, zero explanation why. can we logToFile both branches so it's actually debuggable?

Fernando Gomes added 7 commits July 16, 2026 09:24
Generated-By: PostHog Code
Task-Id: 479c28e8-6980-43b3-88a1-71cfdc39fbce
Generated-By: PostHog Code
Task-Id: 479c28e8-6980-43b3-88a1-71cfdc39fbce
Generated-By: PostHog Code
Task-Id: 479c28e8-6980-43b3-88a1-71cfdc39fbce
Generated-By: PostHog Code
Task-Id: 479c28e8-6980-43b3-88a1-71cfdc39fbce
Generated-By: PostHog Code
Task-Id: 479c28e8-6980-43b3-88a1-71cfdc39fbce
Generated-By: PostHog Code
Task-Id: 479c28e8-6980-43b3-88a1-71cfdc39fbce
Generated-By: PostHog Code
Task-Id: 479c28e8-6980-43b3-88a1-71cfdc39fbce
@fercgomes
fercgomes force-pushed the posthog-code/stream-event-plan-headless branch from 4a5f328 to cc23e5b Compare July 16, 2026 12:25

fercgomes commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Merge activity

  • Jul 16, 12:31 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jul 16, 12:31 PM UTC: @fercgomes merged this pull request with Graphite.

@fercgomes
fercgomes merged commit dcaf90f into main Jul 16, 2026
16 checks passed
@fercgomes
fercgomes deleted the posthog-code/stream-event-plan-headless branch July 16, 2026 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants